#ifndef __FOC_CONTROLLER_H__
#define __FOC_CONTROLLER_H__


#define MOTOR_PP                        7.0f					/* 电机极对数 */

#define M_PI    						(3.14159265359f)
#define _2PI  						    (6.28318530718f)
#define PI       						(3.14159265359f)

#define AngleToRad(x) 					(1.0 * (x) * PI / 180)

#define MIN_ANGLE_DETECT_MOVEMENT 		(_2PI/101.0f)

#define _isset(a) ( (a) != (NOT_SET) )

#define NOT_SET -12345.0f

/* PWM 计数周期 */
#define DRV_PWM                 (4096.0f)



typedef enum
{
	FOC_TYPE_POSITION = 0,
    FOC_TYPE_SPEED,
    FOC_TYPE_CURRENT,
    FOC_TYPE_KNOB
}foc_type_t;



typedef struct
{
    float ia;
    float ib;
    float ic;
    
    float ialpha;
    float ibeta;
    
    float iq;
    float id;
    
    float uq;
    float ud;
    
    float ualpha;
    float ubeta;
    
    float ua;
    float ub;
    float uc;
    
    float angle;
    float position;
    float ele_rad;
    float speed;
    
    float iq_ref;
    float id_ref;
    float speed_ref;
    float position_ref;
    
}foc_controller_t;


void foc_run(void);

void foc_init(void);



void park(foc_controller_t *foc_controller, float _sin, float _cos);

void revpark(foc_controller_t *foc_controller, float _sin, float _cos);

void clark(foc_controller_t *foc_controller);

double normalize_angle(double angle);

void svpwm(foc_controller_t *foc_controller);



#endif




